<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
 * Class SystemUserAuth
 *
 * @property int $id
 * @property int $user_id
 * @property string $identity_type
 * @property string $identifier
 * @property string $credential
 * @property Carbon $created_at
 * @property Carbon $updated_at
 *
 * @package App\Models
 */
class Base extends Model
{
    protected $guarded =[];
    /**
     * assign 对象赋值
     * @time:2020/2/5-11:29
     * @param array $data
     * @author:dongdong
     */
    public function assign(array $data)
    {
        $attributes = $this->getFillable();
        if (empty($attributes)) {
            foreach ($data as $attribute=>$attributeVal)
            {
                $this->$attribute = $attributeVal;
            }
        }

        else {
            foreach ($data as $attribute => $attributeVal)
            {
                foreach ($attributes as $attributeItem) {
                    if ($attributeItem ==  $attribute)  {
                        $this->$attributeItem = $attributeVal;
                    }
                }
            }
        }

        return $this;
    }
}
